package cn.tedu.file;

import sun.plugin2.gluegen.runtime.BufferFactory;

import java.io.*;

/*本类用于测试字符输入流Reader的读取操作*/
public class TestIn2 {
    public static void main(String[] args) {
        method1();//用于测试普通字符输入流
        method2();//用于测试高效字符输入流
    }
    //用于测试高效字符输入流的读取操作
    private static void method2() {
        // 创建流对象
        BufferedReader in =null;
        try {
//            in2 =new BufferedReader(new FileReader("D:\\ready\\1.txt"));
            in =new BufferedReader(new FileReader(new File("D:\\ready\\1.txt")));
            //使用流对象
            int a;
            while((a=in.read())!=-1){
                System.out.println(a);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            //关流
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    //用于测试普通字符输入流的读取操作
    private static void method1() {
        FileReader in = null;
        try {
            //创建流对象
//            FileReader in2 = new FileReader(new File("D:\\ready\\1.txt"));
            in = new FileReader("D:\\ready\\1.txt");
            //使用流对象
            int b;
            while((b=in.read())!=-1){//只要读到的数据不是-1,继续循环
                System.out.println(b);//打印读到的数据
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            //关流
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
